﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MongoDB.Driver;
using MongoDB.Bson;
using System.Configuration;
using System.Collections.Specialized;
namespace Collection.Services
{
	public class Mongo
	{
		/// <summary>
		/// Mongo服务器
		/// </summary>
		public readonly static MongoDatabase Wanpijie;
		private readonly static MongoServer server;
		private readonly static MongoCredentials credentials;

		/// <summary>
		/// 对Mongo数据操作层进行初始化操作
		/// </summary>
		static Mongo()
		{
			var mongoCollection = (NameValueCollection)ConfigurationManager.GetSection("mongo");
			string[] authString = mongoCollection["credentials"].Split(';');
			server = MongoServer.Create(mongoCollection["connectionString"]);
			credentials = new MongoCredentials(authString[0], authString[1]);
			Wanpijie = server.GetDatabase("Wanpijie", credentials);
		}

		/// <summary>
		/// Mongo数据库中Products对象
		/// </summary>
		public static MongoCollection<BsonDocument> Products
		{
			get
			{
				return Wanpijie.GetCollection<BsonDocument>("pt_SalesInfoExpand");
			}
		}
	}
}
